<template>
    <a-spin :spinning="confirmLoading" :tip="tipMessage">
        <a-form :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">


            <a-row>
                <a-col :span="24">
                    <a-form-model-item label="作息" :labelCol="labelCol_1" :wrapperCol="wrapperCol_1">
                        <a-radio-group v-model="model.breakTypeConfig.value" :options="breakOptions"  />


                        <!--                        <a-radio-group v-model="value" @change="onChange">-->
<!--                            <a-radio  :value="0">-->
<!--                                夏季作息-->
<!--                            </a-radio>-->
<!--                            <a-radio  :value="1">-->
<!--                                冬季作息-->
<!--                            </a-radio>-->
<!--                        </a-radio-group>-->
                    </a-form-model-item>
                </a-col>
            </a-row>

<!--            <a-row>-->
<!--                <a-col :span="24">-->
<!--                    <a-form-model-item label="职位" :labelCol="labelCol_1" :wrapperCol="wrapperCol_1">-->
<!--                        <a-select v-model="model.keyword" mode="tags" style="width: 500px" placeholder="请输入职位"/>-->
<!--                    </a-form-model-item>-->
<!--                </a-col>-->
<!--            </a-row>-->

<!--            <a-row>-->
<!--                <a-col :span="12">-->
<!--                    <a-form-model-item label="执行时间" :labelCol="labelCol_2" :wrapperCol="wrapperCol_2">-->
<!--                        <a-time-picker v-model="model.scheduleTime" :default-open-value="moment('00:00:00', 'HH:mm:ss')"-->
<!--                                       @change="onChange"/>-->

<!--                    </a-form-model-item>-->

<!--                </a-col>-->
<!--                <a-col :span="5">-->
<!--                    <a-form-model-item label="是否开启" :labelCol="labelCol_2" :wrapperCol="wrapperCol_2">-->
<!--                        <a-switch v-model="model.scheduleStatus" checked-children="开" un-checked-children="关"-->
<!--                                  default-checked/>-->
<!--                    </a-form-model-item>-->
<!--                </a-col>-->
<!--            </a-row>-->

<!--            <a-row>-->
<!--                <a-col :span="12">-->
<!--                    <a-form-model-item label="距离下次执行还有" :labelCol="labelCol_2" :wrapperCol="wrapperCol_2">-->
<!--                        {{remainTime}}-->
<!--                    </a-form-model-item>-->
<!--                </a-col>-->
<!--                <a-col :span="5">-->
<!--                    <a-button @click="directRun" type="default" :loading="showLoading"> 立即执行</a-button>-->
<!--                </a-col>-->
<!--            </a-row>-->

            <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
                <!--            <a-button type="primary" html-type="submit">-->
                <!--                Submit-->
                <!--            </a-button>-->

                <a-col :span="12">

                    <a-button @click="save" type="primary" :loading="showLoading"> 保存</a-button>
                    &nbsp;
                    <!--                <a-button @click="cancel()"> 取消 </a-button>-->
                </a-col>
            </a-form-item>

            <!--        <a-form-item v-bind="tailFormItemLayout">-->
            <!--            <a-col :span="12">-->
            <!--                <a-button @click="save()" type="primary" :loading="checkLoading"> 保存 </a-button>-->
            <!--                &nbsp;-->
            <!--&lt;!&ndash;                <a-button @click="cancel()"> 取消 </a-button>&ndash;&gt;-->
            <!--            </a-col>-->
            <!--        </a-form-item>-->
        </a-form>

    </a-spin>
</template>
<script>
    import {FormMixin} from '@/mixins/FormMixin'
    import moment from 'moment';
    import {LocalCache} from '@/utils/localData';
    import {cityList} from '@/api/city';
    import {getDataOptionList} from "../../../utils/util";
    import {getAction, httpAction} from "../../../api/manage";
    const XLSX = require('xlsx');

    // const chrome = {};
    // const methodCallOptions = {actionLoadingField:'checkLoading',msgTip:true};
    export default {
        components: {},
        mixins: [FormMixin],
        data() {
            return {
                confirmLoading: false,
                showLoading: false,
                tipMessage: '',

                model: {
                    breakTypeConfig:{name:'breakType',value:0}
                },
                breakOptions: getDataOptionList('breakTypes'),
                remainTime:'',
                // labelCol: {
                //     xs: { span: 24 },
                //     sm: { span: 5 },
                // },
                // wrapperCol: {
                //     xs: { span: 24 },
                //     sm: { span: 12 },
                // },

                // tailFormItemLayout: {
                //     wrapperCol: {
                //         xs: {
                //             span: 24,
                //             offset: 0,
                //         },
                //         sm: {
                //             span: 16,
                //             offset: 8,
                //         },
                //     },
                // }

            };
        },
        computed: {
            // remainTime() {
            //
            //     function calculateNextAlarmInterval(alarmTime) {
            //         // 获取当前日期和时间
            //         const now = new Date();
            //
            //         // 解析闹钟时间（格式为 "HH:mm:ss"）
            //         const [hours, minutes, seconds] = alarmTime.split(':').map(Number);
            //         const alarmDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), hours, minutes, seconds);
            //
            //         // 如果闹钟时间已经过去，则设置为明天
            //         if (alarmDate <= now) {
            //             alarmDate.setDate(alarmDate.getDate() + 1);
            //         }
            //
            //         // 计算时间差（毫秒）
            //         const diff = alarmDate - now;
            //
            //         // 将时间差转换为 HH:mm:ss 格式
            //         let totalSeconds = Math.floor(diff / 1000);
            //         let hoursLeft = Math.floor(totalSeconds / 3600);
            //         totalSeconds %= 3600;
            //         let minutesLeft = Math.floor(totalSeconds / 60);
            //         let secondsLeft = totalSeconds % 60;
            //
            //         // 格式化为两位数
            //         const pad = (n) => n < 10 ? '0' + n : n;
            //
            //         return `${pad(hoursLeft)}小时${pad(minutesLeft)}分钟${pad(secondsLeft)}秒`;
            //     }
            //
            //     if (this.model.scheduleTime) {
            //         let remainTimeStr = calculateNextAlarmInterval(this.model.scheduleTime.format('HH:mm:ss'));
            //         return remainTimeStr;
            //     } else {
            //         return '';
            //     }
            // },

            // filteredOptions() {
            //     return cityOptions.filter(o => !this.selectedItems.includes(o.label));
            // },
        },
        mounted() {

        },
        created() {
            let $this = this;
            let url = "/system/configList";
            // let params = {appId:$this.dataSourceToBeanParam.appId,dataSourceId:$this.dataSourceToBeanParam.dataSourceId,tableNames:$this.dataSourceToBeanParam,buildProcess:$this.buildProcess,hisVersion:$this.hisVersion};
            // let res = await getAction(url, {month: record.month, name: record.name});
            // this.dataSourceList = res.data
            $this.confirmLoading = true
            getAction(url, {}).then((res) => {
                if (res.success) {
                    //修改
                    let resData = res.data;
                    if(resData && resData.length > 0){
                        let breakTypeConfig = resData.find(function(item){
                            return item.name == 'breakType'
                        })
                        $this.model.breakTypeConfig.value = parseInt(breakTypeConfig.value);
                        // debugger
                    }
                } else {
                    $this.$message.warning(res.message);
                }
            }).finally(() => {
                $this.confirmLoading = false;
            })

        },
        methods: {
            init() {

            },
            moment,
            // onChange(time, timeString) {
            //     console.log(time, timeString);
            // },
            // filterOption(input, option) {
            //     return (
            //         option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
            //     );
            // },

            save() {
                const $this = this;
                $this.confirmLoading = true;
                // $this.tipMessage = '';
                console.log($this.model);


                httpAction('/system/saveConfig',$this.model.breakTypeConfig, "post").then((res) => {
                    if (res.success) {
                        $this.$message.success(res.message || '保存成功');
                        $this.$emit('ok');
                    } else {
                        $this.$message.warning(res.message);
                    }
                }).catch(function (e) {
                    console.error(e);
                    $this.$message.error(e.response.data.message);
                }).finally(() => {
                    $this.confirmLoading = false;
                })
            },

            // directRun() {
            //     const $this = this;
            //     console.log($this.model);
            //     if (!$this.model.city) {
            //         this.$message.warning('请选择城市');
            //         return;
            //     } else if ($this.model.city.length > 5) {
            //         this.$message.warning('最多只能选择5个城市');
            //         return;
            //     }
            //     if (!$this.model.keyword) {
            //         this.$message.warning('请输入职位');
            //         return;
            //     } else if ($this.model.keyword.length > 5) {
            //         this.$message.warning('最多只能选择5个职位');
            //         return;
            //     }
            //     // if(!$this.model.scheduleTime){
            //     //     this.$message.warning('执行时间不能为空');
            //     //     return;
            //     // }
            //
            //
            //     // const scheduleTime = $this.model.scheduleTime.valueOf();
            //     // const scheduleStatus = $this.model.scheduleStatus;
            //     let data = {
            //         city: $this.model.city,
            //         keyword: $this.model.keyword,
            //     };
            //     console.log(data)
            //     chrome.runtime.sendMessage({success: true, type: 'pullTask', data: data});
            //     // LocalCache.set('settingsData',data)
            //     this.$message.success('操作成功');
            //
            // },
            // exportXls(data) {
            //     // 创建一个工作簿
            //     const workbook = XLSX.utils.book_new();
            //     const worksheet = XLSX.utils.aoa_to_sheet(data);
            //     XLSX.utils.book_append_sheet(workbook, worksheet, "Sheet1");
            //     const excelData = XLSX.write(workbook, {bookType: 'xlsx', type: 'binary'});
            //     function s2ab(s) {
            //         const buf = new ArrayBuffer(s.length);
            //         const view = new Uint8Array(buf);
            //         for (let i = 0; i < s.length; i++) {
            //             view[i] = s.charCodeAt(i) & 0xFF;
            //         }
            //         return buf;
            //     }
            //
            //     const blob = new Blob([s2ab(excelData)], {type: 'application/octet-stream'});
            //     const url = window.URL.createObjectURL(blob);
            //     const a = document.createElement('a');
            //     a.href = url;
            //     a.download = 'data.xlsx';
            //     a.click();
            //     window.URL.revokeObjectURL(url);
            // }
            // cancel(){
            //     const $this = this;
            //     methodCall(this,'settings','getInitData',this.model,{msgTip:false},function(res){
            //         if(res.success){
            //             // $this.model = JSON.parse(JSON.stringify(res.data));
            //             $this.model = res.data;
            //         }
            //     });
            // },
            //
            // async exec2(id) {
            //     const params = {
            //         id: id
            //     }
            //     requestHttp(ipcApiRoute.test, params).then(res => {
            //         console.log('res2:', res)
            //     })
            //
            //
            // },
        }
    };
</script>
<style lang="less" scoped>
    /*#app-base-test-api {*/
    /*    padding: 5px 10px;*/
    /*    text-align: left;*/
    /*    width: 100%;*/

    /*    .one-block-1 {*/
    /*        font-size: 16px;*/
    /*        padding-top: 10px;*/
    /*    }*/

    /*    .one-block-2 {*/
    /*        padding-top: 10px;*/
    /*    }*/
    /*    .one-block-3 {*/
    /*        padding-top: 3px;*/
    /*    }*/
    /*}*/
</style>
